﻿namespace ElisVK.Data.AudioSources
{
    using System.Text;
    using Utils;

    public class VKGroupsAudioSource : AudioSource
    {
        public VKGroupsAudioSource()
            : base("VK Groups", true)
        {
        }
        
        protected override void LoadChildren()
        {
            var buff = VKHelper.DownloadData(
                "https://api.vkontakte.ru/method/groups.get.xml?extended=1&access_token=" +
                App.SessionInfo.AccessToken);

            var groupssList = GroupInfo.ParseUserInfosFromXML(Encoding.UTF8.GetString(buff));

            groupssList.Sort();

            foreach (var group in groupssList)
            {
                Children.Add(new VKGroupAudioSource(group));
            }
        }
    }
}
